package com.moqianfan.mcuassistant.activity

import android.os.Handler
import com.alibaba.android.arouter.launcher.ARouter
import com.limh.base.AppConfig
import com.limh.base.comm.Comm
import com.limh.base.dao.Session
import com.limh.base.router.RouterPath
import com.limh.base.utils.GsonUtils
import com.limh.base.utils.Logs
import com.limh.base.utils.SpUtils
import com.moqianfan.mcuassistant.R


/**
 * @function：启动页面
 * @author： limh
 * @date： 2018/8/18
 * Copyright @2018 Corpration Name
 */
class SplashActivity : BaseActivity() {
    override fun findView() {
        setContentView(R.layout.activity_splash)
    }

    override fun initViews() {

    }

    override fun initDatas() {

    }

    override fun onWindowFocusChanged(hasFocus: Boolean) {
        super.onWindowFocusChanged(hasFocus)
        val spMsg = SpUtils.get(this, Comm.SESSION, "") as String
        val path: String
        if (spMsg.isEmpty()) {
            path = RouterPath.UserModule.path_user_login
        } else {
            path = RouterPath.AppModule.path_app_main
            AppConfig.instance.token = GsonUtils.str2Bean(spMsg, Session::class.java).token
            AppConfig.instance.refreshToken = GsonUtils.str2Bean(spMsg, Session::class.java).refreshToken
        }
        Logs.d(TAG, "spMsg=$spMsg  path=$path")
        if (hasFocus) {
            Handler().postDelayed({
                ARouter.getInstance().build(path).navigation()
                finish()
            }, 2000)
        }
    }
}